home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / WEDL203.ARJ / DEMO.C < prev    next >
C/C++ Source or Header  |  1992-07-30  |  38KB  |  923 lines

  1.  
  2. /*---------------------------------------------------------------------------*/
  3. /*                                                                           */
  4. /*          WEDL(tm) - Windows Enhanced Dialog Library                       */
  5. /*          Copyright (c) 1991-1992, Nemisoft, Inc.                          */
  6. /*          All Rights Reserved                                              */
  7. /*          Module:  DEMO.C                                                  */
  8. /*                                                                           */
  9. /*---------------------------------------------------------------------------*/
  10.  
  11. #include <windows.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include "wedl.h"
  16. #include "demo.h"
  17. #include "demohelp.h"
  18.  
  19. /*---------------------------------------------------------------------------*/
  20.  
  21. /* general function prototypes */
  22.  
  23. int FAR PASCAL AboutDlgProc( HWND hDlg, unsigned message, WORD wParam,
  24.                              LONG lParam );
  25. int FAR PASCAL AlbumDlgProc( HWND hDlg, unsigned message, WORD wParam,
  26.                              LONG lParam );
  27. int FAR PASCAL EmployeeDlgProc( HWND hDlg, unsigned message, WORD wParam,
  28.                                 LONG lParam );
  29. int FAR PASCAL check_date( HFORM hform, HFIELD hfield, LPSTR pbuf );
  30. int FAR PASCAL check_file_name( HFORM hform, HFIELD hfield, LPSTR pbuf );
  31. int FAR PASCAL check_state( HFORM hform, HFIELD hfield, LPSTR pbuf );
  32. int FAR PASCAL check_zip_code( HFORM hform, HFIELD hfield, LPSTR pbuf );
  33. BOOL FAR PASCAL error_func( HFORM hform, HFIELD hfield, int error_value,
  34.                             int error_position, int error_event );
  35. static BOOL initialize_application( HANDLE hInstance );
  36. static BOOL initialize_instance( HANDLE hInstance, int nCmdShow );
  37. long FAR PASCAL MainWndProc( HWND hWnd, unsigned message, WORD wParam,
  38.                              LONG lParam );
  39. int FAR PASCAL NumericDlgProc( HWND hDlg, unsigned message, WORD wParam,
  40.                                LONG lParam );
  41. int FAR PASCAL UploadDlgProc( HWND hDlg, unsigned message, WORD wParam,
  42.                              LONG lParam );
  43.  
  44. /*---------------------------------------------------------------------------*/
  45.  
  46. /* static variables (global to this file) */
  47.  
  48. static HINSTANCE hInst;
  49. static HBITMAP hBitmap;
  50. static BITMAP bitmap;
  51. static char szClassName[] = "WEDL_DEMO";
  52. static char help_file_name[] = "demohelp.hlp";
  53. static char tbuf[512];
  54. static PVALFUNC pcheck_date, pcheck_state, pcheck_zip_code, pcheck_file_name;
  55. static PERRFUNC perror_func;
  56.  
  57. /*---------------------------------------------------------------------------*/
  58.  
  59. int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
  60.                     int nCmdShow )
  61. {
  62.     MSG msg;
  63.  
  64.     if( hPrevInstance == NULL )
  65.         if( !initialize_application( hInstance ) ) return( FALSE );
  66.  
  67.     if( !initialize_instance( hInstance, nCmdShow ) ) return( FALSE );
  68.  
  69.     while( GetMessage( &msg, NULL, 0, 0 ) ) {
  70.         TranslateMessage( &msg );
  71.         DispatchMessage( &msg );
  72.     }
  73.  
  74.     DeleteObject( hBitmap );
  75.  
  76.     return( msg.wParam );
  77. }
  78.  
  79. /*---------------------------------------------------------------------------*/
  80.  
  81. long FAR PASCAL MainWndProc( HWND hWnd, unsigned message, WORD wParam,
  82.                              LONG lParam )
  83. {
  84.     FARPROC pdialog_proc;
  85.     HDC hDC, hMemDC;
  86.     PAINTSTRUCT paint;
  87.  
  88.     switch( message ) {
  89.  
  90.         case WM_PAINT:
  91.             hDC     = BeginPaint( hWnd, &paint );
  92.             hMemDC  = CreateCompatibleDC( hDC );
  93.             SelectObject( hMemDC, hBitmap );
  94.             BitBlt( hDC, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hMemDC,
  95.                     0, 0, SRCCOPY );
  96.             DeleteDC( hMemDC );
  97.             EndPaint( hWnd, &paint );
  98.             break;
  99.  
  100.         case WM_COMMAND:
  101.             switch( wParam ) {
  102.                 case IDM_EMPLOYEE:
  103.                     pdialog_proc    = MakeProcInstance( EmployeeDlgProc, hInst );
  104.                     pcheck_date     = (PVALFUNC) MakeProcInstance( check_date, hInst );
  105.                     pcheck_state    = (PVALFUNC) MakeProcInstance( check_state, hInst );
  106.                     pcheck_zip_code = (PVALFUNC) MakeProcInstance( check_zip_code, hInst );
  107.                     perror_func     = (PERRFUNC) MakeProcInstance( error_func, hInst );
  108.                     DialogBox( hInst, "EmployeeInfo", hWnd, pdialog_proc );
  109.                     FreeProcInstance( perror_func );
  110.                     FreeProcInstance( pcheck_zip_code );
  111.                     FreeProcInstance( pcheck_state );
  112.                     FreeProcInstance( pcheck_date );
  113.                     FreeProcInstance( pdialog_proc );
  114.                     break;
  115.                 case IDM_ALBUM:
  116.                     pdialog_proc = MakeProcInstance( AlbumDlgProc, hInst );
  117.                     DialogBox( hInst, "AlbumDatabase", hWnd, pdialog_proc );
  118.                     FreeProcInstance( pdialog_proc );
  119.                     break;
  120.                 case IDM_UPLOAD:
  121.                     pdialog_proc     = MakeProcInstance( UploadDlgProc,   hInst );
  122.                     pcheck_file_name = (PVALFUNC) MakeProcInstance( check_file_name, hInst );
  123.                     perror_func      = (PERRFUNC) MakeProcInstance( error_func,      hInst );
  124.                     DialogBox( hInst, "UploadFile", hWnd, pdialog_proc );
  125.                     FreeProcInstance( perror_func );
  126.                     FreeProcInstance( pcheck_file_name );
  127.                     FreeProcInstance( pdialog_proc );
  128.                     break;
  129.                 case IDM_NUMERIC:
  130.                     pdialog_proc = MakeProcInstance( NumericDlgProc, hInst );
  131.                     DialogBox( hInst, "NumericFields", hWnd, pdialog_proc );
  132.                     FreeProcInstance( pdialog_proc );
  133.                     break;
  134.                 case IDM_EXIT:
  135.                     SendMessage( hWnd, WM_CLOSE, 0, 0 );
  136.                     break;
  137.                 case IDM_ABOUT:
  138.                     pdialog_proc = MakeProcInstance( AboutDlgProc, hInst );
  139.                     DialogBox( hInst, "AboutWEDL", hWnd, pdialog_proc );
  140.                     FreeProcInstance( pdialog_proc );
  141.                     break;
  142.             }
  143.             break;
  144.         case WM_DESTROY:
  145.             PostQuitMessage( 0 );
  146.             break;
  147.         default:
  148.             return( DefWindowProc( hWnd, message, wParam, lParam ) );
  149.     }
  150.     return( 0 );
  151. }
  152.  
  153. /*---------------------------------------------------------------------------*/
  154.  
  155. int FAR PASCAL AboutDlgProc( HWND hDlg, unsigned message, WORD wParam,
  156.                              LONG lParam )
  157. {
  158.     switch( message ) {
  159.         case WM_INITDIALOG:
  160.             return( TRUE );
  161.         case WM_COMMAND:
  162.             if( wParam == IDOK || wParam == IDCANCEL ) {
  163.                 EndDialog( hDlg, TRUE );
  164.                 return( TRUE );
  165.             }
  166.             break;
  167.     }
  168.     return( FALSE );
  169. }
  170.  
  171. /*---------------------------------------------------------------------------*/
  172.  
  173. static BOOL initialize_application( HANDLE hInstance )
  174. {
  175.     WNDCLASS wc;
  176.  
  177.     wc.style         = NULL;
  178.     wc.lpfnWndProc   = (WNDPROC) MainWndProc;
  179.     wc.cbClsExtra    = 0;
  180.     wc.cbWndExtra    = 0;
  181.     wc.hInstance     = hInstance;
  182.     wc.hIcon         = LoadIcon( hInstance, "WEDL" );
  183.     wc.hCursor       = LoadCursor( NULL, IDC_ARROW );
  184.     wc.hbrBackground = GetStockObject( NULL_BRUSH );
  185.     wc.lpszMenuName  = "MainMenu";
  186.     wc.lpszClassName = szClassName;
  187.  
  188.     return( RegisterClass( &wc ) );
  189. }
  190.  
  191. /*---------------------------------------------------------------------------*/
  192.  
  193. static BOOL initialize_instance( HANDLE hInstance, int nCmdShow )
  194. {
  195.     HWND hWnd;
  196.     int ht_border, ht_caption, ht_menu, wd_border;
  197.  
  198.     hInst = hInstance;
  199.  
  200.     wd_border  = GetSystemMetrics( SM_CXBORDER );
  201.     ht_border  = GetSystemMetrics( SM_CYBORDER );
  202.     ht_caption = GetSystemMetrics( SM_CYCAPTION );
  203.     ht_menu    = GetSystemMetrics( SM_CYMENU );
  204.  
  205.     hBitmap = LoadBitmap( hInstance, "WEDL" );
  206.     GetObject( hBitmap, sizeof( BITMAP ), (LPSTR) &bitmap );
  207.  
  208.     hWnd = CreateWindow(
  209.                 szClassName, "WEDL Demonstration Program",
  210.                 WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION  | WS_MINIMIZEBOX,
  211.                 65, 35, bitmap.bmWidth + wd_border + wd_border,
  212.                 bitmap.bmHeight + ht_border + ht_border + ht_caption + ht_menu,
  213.                 NULL, NULL, hInstance, NULL );
  214.  
  215.     if( hWnd == NULL ) return( FALSE );
  216.  
  217.     ShowWindow( hWnd, nCmdShow );
  218.     UpdateWindow( hWnd );
  219.     return( TRUE );
  220. }
  221.  
  222. /*---------------------------------------------------------------------------*/
  223.  
  224. BOOL FAR PASCAL error_func( HFORM hform, HFIELD hfield, int error_value,
  225.                             int error_position, int error_event )
  226. {
  227.     HWND hDlg;
  228.  
  229.     hDlg = form_get_hdlg( hform );
  230.     switch( error_value ) {
  231.         case BAD_DATE:
  232.             MessageBox( hDlg, "Date Is Invalid", NULL, MB_OK );
  233.             break;
  234.         case BAD_STATE:
  235.             MessageBox( hDlg, "Invalid State Code", NULL, MB_OK );
  236.             break;
  237.         case BAD_ZIP:
  238.             MessageBox( hDlg, error_position > 1 ? "Zip Code is incomplete"
  239.                         : "Zip code is invalid for given State", NULL, MB_OK );
  240.             break;
  241.         case BAD_FILENAME:
  242.             MessageBox( hDlg, "File Not In Directory", NULL, MB_OK );
  243.             break;
  244.         default:
  245.             return( FALSE );        /* error wasn't handled */
  246.     }
  247.     return( TRUE );                 /* error was handled */
  248. }
  249.  
  250. /*****************************************************************************/
  251. /*---------------------------------------------------------------------------*/
  252. /*---------------------------------------------------------------------------*/
  253. /*------------------------/                           \----------------------*/
  254. /*------------------------ Employee Information Dialog ----------------------*/
  255. /*------------------------\                           /----------------------*/
  256. /*---------------------------------------------------------------------------*/
  257. /*---------------------------------------------------------------------------*/
  258. /*****************************************************************************/
  259.  
  260. #define IDHELP 998
  261.  
  262. /*---------------------------------------------------------------------------*/
  263.  
  264. /* state/ZIP code table */
  265.  
  266. struct states_t {
  267.     PSTR state_code;
  268.     int zip_low;
  269.     int zip_high;
  270. };
  271.  
  272. static struct states_t states[] = {
  273.     { "AK", 995, 999 },     /* Alaska               */
  274.     { "AL", 350, 369 },     /* Alabama              */
  275.     { "AR", 716, 729 },     /* Arkansas             */
  276.     { "AZ", 850, 865 },     /* Arizona              */
  277.     { "CA", 900, 961 },     /* California           */
  278.     { "CO", 800, 816 },     /* Colorado             */
  279.     { "CT",  60,  69 },     /* Connecticut          */
  280.     { "DE", 197, 199 },     /* Delaware             */
  281.     { "FL", 320, 349 },     /* Florida              */
  282.     { "GA", 300, 319 },     /* Georgia              */
  283.     { "HI", 967, 968 },     /* Hawaii               */
  284.     { "IA", 500, 528 },     /* Iowa                 */
  285.     { "ID", 832, 847 },     /* Idaho                */
  286.     { "IL", 600, 629 },     /* Illinois             */
  287.     { "IN", 460, 479 },     /* Indiana              */
  288.     { "KS", 641, 679 },     /* Kansas               */
  289.     { "KY", 400, 427 },     /* Kentucky             */
  290.     { "LA", 700, 714 },     /* Louisiana            */
  291.     { "MA",  10,  27 },     /* Massachusetts        */
  292.     { "MD", 206, 219 },     /* Maryland             */
  293.     { "ME",  39,  49 },     /* Maine                */
  294.     { "MI", 480, 499 },     /* Michigan             */
  295.     { "MN", 550, 567 },     /* Minnesota            */
  296.     { "MO", 630, 658 },     /* Missouri             */
  297.     { "MS", 386, 397 },     /* Mississippi          */
  298.     { "MT", 590, 599 },     /* Montana              */
  299.     { "NC", 270, 289 },     /* North Carolina       */
  300.     { "ND", 580, 588 },     /* North Dakota         */
  301.     { "NE", 680, 693 },     /* Nebraska             */
  302.     { "NH",  30,  38 },     /* New Hampshire        */
  303.     { "NJ",  70,  89 },     /* New Jersey           */
  304.     { "NM", 870, 884 },     /* New Mexico           */
  305.     { "NV", 889, 898 },     /* Nevada               */
  306.     { "NY", 100, 149 },     /* New York             */
  307.     { "OH", 430, 458 },     /* Ohio                 */
  308.     { "OK", 730, 749 },     /* Oklahoma             */
  309.     { "OR", 970, 979 },     /* Oregon               */
  310.     { "PA", 150, 196 },     /* Pennsylvania         */
  311.     { "RI",  27,  29 },     /* Rhode Island         */
  312.     { "SC", 290, 299 },     /* South Carolina       */
  313.     { "SD", 570, 577 },     /* South Dakota         */
  314.     { "TN", 370, 385 },     /* Tennessee            */
  315.     { "TX", 750, 885 },     /* Texas                */
  316.     { "UT", 840, 847 },     /* Utah                 */
  317.     { "VA", 220, 246 },     /* Virginia             */
  318.     { "VT",  50,  59 },     /* Vermont              */
  319.     { "WA", 980, 994 },     /* Washington           */
  320.     { "WI", 530, 549 },     /* Wisconsin            */
  321.     { "WV", 247, 268 },     /* West Virginia        */
  322.     { "WY", 820, 831 },     /* Wyoming              */
  323.     { "DC", 200, 205 },     /* District of Columbia */
  324.     { "GU",   0, 999 },     /* Guam                 */
  325.     { "PR",   0, 999 },     /* Puerto Rico          */
  326.     { "VI",   0, 999 },     /* Virgin Islands       */
  327.     { "ON",   0, 999 },     /* Ontario              */
  328.     { "PQ",   0, 999 },     /* Quebec               */
  329.     { "BC",   0, 999 },     /* British Columbia     */
  330.     { "AB",   0, 999 },     /* Alberta              */
  331.     { "SK",   0, 999 },     /* Saskatchewan         */
  332.     { "MB",   0, 999 },     /* Manitoba             */
  333.     { "NS",   0, 999 },     /* Nova Scotia          */
  334.     { "NB",   0, 999 },     /* New Brunswick        */
  335.     { "NF",   0, 999 },     /* Newfoundland         */
  336.     { "PE",   0, 999 },     /* Prince Edward Island */
  337.     { NULL,   0,   0 }      /* --- end of table --- */
  338. };
  339.  
  340. /*---------------------------------------------------------------------------*/
  341.  
  342. int FAR PASCAL EmployeeDlgProc( HWND hDlg, unsigned message, WORD wParam,
  343.                                 LONG lParam )
  344. {
  345.     static HFORM hform = NULL;
  346.     static char first_name[16]="", mid_init[2]="", last_name[21]="";
  347.     static char address[31]="", city[16]="", state[3]="", zip_code[10]="";
  348.     static char soc_sec_no[10]="", phone_num[11]="", hire_date[9]="";
  349.     static double wage = 0.0;
  350.  
  351.     switch( message ) {
  352.         case WM_INITDIALOG:
  353.             hform = form_begin( hDlg, FMF_NOSELECT | FMF_VKEYPRES |
  354.                                 FMF_VLEAVFLD | FMF_UPDATE | FMF_OVERTYPE,
  355.                                 perror_func );
  356.             form_set_help( hform, help_file_name, 0 );
  357.             field_define( hform, IDD_SSN, soc_sec_no, FDT_STRING,
  358.                           "<0..7>99'-'99'-'9(4)", FDF_NOTBLANK | FDF_COMPLETE,
  359.                           NULL, 0, IDH_SSN );
  360.             field_define( hform, IDD_FNAME, first_name, FDT_STRING,
  361.                           "A(15)", FDF_PROPER,
  362.                           NULL, 0, IDH_FNAME );
  363.             field_define( hform, IDD_MIDINIT, mid_init, FDT_STRING,
  364.                           "A(1)'.'",  FDF_UPPER, NULL, 0, IDH_MIDINIT );
  365.             field_define( hform, IDD_LNAME, last_name, FDT_STRING,
  366.                           "<A..Z>A(19)", FDF_PROPER,
  367.                           NULL, 0, IDH_LNAME );
  368.             field_define( hform, IDD_ADDRESS, address, FDT_STRING,
  369.                           "?(30)", FDF_PROPER,
  370.                           NULL, 0, IDH_ADDRESS );
  371.             field_define( hform, IDD_CITY, city, FDT_STRING,
  372.                           "?(15)", FDF_PROPER,
  373.                           NULL, 0, IDH_CITY );
  374.             field_define( hform, IDD_STATE, state, FDT_STRING,
  375.                           "A(2)", FDF_COMPLETE | FDF_UPPER,
  376.                           pcheck_state, BAD_STATE, IDH_STATE );
  377.             field_define( hform, IDD_ZIP, zip_code, FDT_STRING,
  378.                           "<0..9>(5)'-'9(4)", FDF_NONE,
  379.                           pcheck_zip_code, BAD_ZIP, IDH_ZIP );
  380.             field_define( hform, IDD_PHONE, phone_num, FDT_STRING,
  381.                           "'('999') '999'-'9999", FDF_COMPLETE,
  382.                           NULL, 0, IDH_PHONE );
  383.             field_define( hform, IDD_HIREDATE, hire_date, FDT_STRING,
  384.                           " <01> 9 / <0123> 9 / <89> 9 ", FDF_COMPLETE |
  385.                           FDF_PHYSICAL, pcheck_date, BAD_DATE, IDH_HIREDATE );
  386.             field_define( hform, IDD_WAGE, &wage, FDT_DOUBLE,
  387.                           "'$'999999.99", FDF_NUMERIC | FDF_BLNKZERO |
  388.                           FDF_BLNKNEZ, NULL, 0, IDH_WAGE );
  389.             keystat_define( hform, IDD_INSERT, KSM_INSERT, "Insert: On",
  390.                             "Insert: Off" );
  391.             generic_define( hform, IDHELP, 0 );
  392.             form_end( hform );
  393.             return( TRUE );
  394.  
  395.         case WM_COMMAND:
  396.             switch( wParam ) {
  397.                 case IDOK:
  398.                     form_ok( hform );
  399.                     EndDialog( hDlg, TRUE );
  400.                     sprintf( tbuf, "Soc Sec No.\t= %s\n"
  401.                              "Name\t\t= %s %s. %s\nAddress\t\t= %s\n"
  402.                              "\t\t= %s, %s %.5s-%s\nPhone No.\t= %s\n"
  403.                              "Hire Date\t= %s\nWage/Salary\t= %.2lf",
  404.                              soc_sec_no, first_name, mid_init, last_name,
  405.                              address, city, state, zip_code, zip_code+5,
  406.                              phone_num, hire_date, wage );
  407.                     MessageBox( NULL, tbuf, "Field Contents", MB_OK );
  408.                     return( TRUE );
  409.                 case IDCANCEL:
  410.                     form_cancel( hform );
  411.                     EndDialog( hDlg, TRUE );
  412.                     return( TRUE );
  413.                 case IDHELP:
  414.                     WinHelp( hDlg, help_file_name, HELP_INDEX, NULL );
  415.                     return( TRUE );
  416.             }
  417.             break;
  418.  
  419.         case WM_CLOSE:
  420.             SendMessage( hDlg, WM_COMMAND, IDCANCEL, 0 );
  421.             return( TRUE );
  422.     }
  423.     return( FALSE );
  424. }
  425.  
  426. /*---------------------------------------------------------------------------*/
  427.  
  428. int FAR PASCAL check_date( HFORM hform, HFIELD hfield, LPSTR pbuf )
  429. {
  430.     char date[10];
  431.     int month, day, year;
  432.  
  433.     if( !str_is_blank( pbuf ) ) {
  434.  
  435.         /* parse year, day, and month from buffer */
  436.         lstrcpy( date, pbuf );
  437.         year = 1900 + atoi( date+4 );
  438.         *( date+4 ) = '\0';
  439.         day = atoi( date+2 );
  440.         *( date+2 ) = '\0';
  441.         month = atoi( date );
  442.  
  443.         /* validate month */
  444.         if( month > 12 ) return( 1 );
  445.  
  446.         /* validate day and month */
  447.         if( day < 1 ) return( 3 );
  448.         switch( month ) {
  449.             case 2:
  450.                 if( year%4 ) {
  451.                     if( day > 29 ) return( 3 );
  452.                 }
  453.                 else {
  454.                     if( day > 28 ) return( 3 );
  455.                 }
  456.                 break;
  457.             case 1:
  458.             case 3:
  459.             case 5:
  460.             case 7:
  461.             case 8:
  462.             case 10:
  463.             case 12:
  464.                 if( day > 31 ) return( 3 );
  465.                 break;
  466.             case 4:
  467.             case 6:
  468.             case 9:
  469.             case 11:
  470.                 if( day > 30 ) return( 3 );
  471.                 break;
  472.             default:
  473.                 return( 1 );
  474.         }
  475.     }
  476.  
  477.     /* return zero indicating no error */
  478.     return( 0 );
  479. }
  480.  
  481. /*---------------------------------------------------------------------------*/
  482.  
  483. int FAR PASCAL check_state( HFORM hform, HFIELD hfield, LPSTR pbuf )
  484. {
  485.     int i;
  486.  
  487.     /* allow state to be blank */
  488.     if( str_is_blank( pbuf ) ) return( 0 );
  489.  
  490.     /* do for all state codes in the table */
  491.     for( i = 0 ; states[i].state_code != NULL ; i++ )
  492.  
  493.         /* if state code was found, then no error */
  494.         if( !lstrcmp( states[i].state_code, pbuf ) ) return( 0 );
  495.  
  496.     /* not a legal 2-letter state code */
  497.     return( 1 );
  498. }
  499.  
  500. /*---------------------------------------------------------------------------*/
  501.  
  502. int FAR PASCAL check_zip_code( HFORM hform, HFIELD hfield, LPSTR pbuf )
  503. {
  504.     LPSTR p;
  505.     int i, num_spaces;
  506.     long zip, zip_low, zip_high;
  507.  
  508.     /* allow zip code to be blank */
  509.     if( str_is_blank( pbuf ) ) return( 0 );
  510.  
  511.     /* count spaces in the extended portion of the 9-digit zip code */
  512.     num_spaces = 0;
  513.     for( p = pbuf + 5 ; *p != '\0' ; p++ ) if( *p == ' ' ) num_spaces++;
  514.  
  515.     /* if zip code isn't exactly 5 or 9 digits, then there's an error */
  516.     if( num_spaces != 0 && num_spaces != 4 ) return( 6 );
  517.  
  518.     *( pbuf+5 ) = '\0';
  519.     field_log_to_data( hfield, pbuf, &zip, FDT_LONG );
  520.  
  521.     /* find matching state */
  522.     hfield = field_get_from_ctrl_id( hform, IDD_STATE );
  523.     field_get_text( hfield, tbuf, FALSE );
  524.     for( i = 0 ; states[i].state_code != NULL ; i++ ) {
  525.         if( !lstrcmp( tbuf, states[i].state_code ) ) break;
  526.     }
  527.     if( states[i].state_code == NULL ) return( 0 );
  528.  
  529.     /* test zip code */
  530.     zip_low  = ( (long) ( states[i].zip_low ) ) * 100L;
  531.     zip_high = ( (long) ( states[i].zip_high ) ) * 100L;
  532.     if( zip >= zip_low && zip <= zip_high ) return( 0 );
  533.     return( 1 );
  534. }
  535.  
  536. /*****************************************************************************/
  537. /*---------------------------------------------------------------------------*/
  538. /*---------------------------------------------------------------------------*/
  539. /*------------------------/                          \-----------------------*/
  540. /*------------------------    Album Database Dialog   -----------------------*/
  541. /*------------------------\                          /-----------------------*/
  542. /*---------------------------------------------------------------------------*/
  543. /*---------------------------------------------------------------------------*/
  544. /*****************************************************************************/
  545.  
  546. /* prototypes for Album Database dialog */
  547.  
  548. static void fill_media_list_box( HWND hDlg );
  549. static int get_record( int recno );
  550. static BOOL okay_to_save_changes( HWND hDlg );
  551. static void update_record( int recno );
  552.  
  553. /*---------------------------------------------------------------------------*/
  554.  
  555. /* albums "file" */
  556.  
  557. struct albums_t {
  558.     char artist[25+1];
  559.     char title[30+1];
  560.     char label[15+1];
  561.     int copyright;
  562.     char media[15+1];
  563. };
  564.  
  565. static struct albums_t albums[] = {
  566.     { "Aerosmith", "Pump", "Geffen", 1989, "Compact Disc" },
  567.     { "Bell Biv Devoe", "Poison", "MCA", 1990, "Cassette" },
  568.     { "The Cure", "Disintegration", "Elektra", 1989, "Compact Disc" },
  569.     { "Front 242", "Front by Front", "Wax Trax", 1988, "Compact Disc" },
  570.     { "INXS", "Kick", "Atlantic", 1987, "Cassette" },
  571.     { "Janet Jackson", "Control", "A&M", 1986, "Cassette" },
  572.     { "Kenny G", "Live", "Arista", 1989, "Compact Disc" },
  573.     { "R.E.M.", "Out of Time", "Warner Bros.", 1991, "Cassette" },
  574.     { "Sex Pistols", "Never Mind the Bollocks", "Warner Bros.", 1977, "Record" },
  575.     { "Van Halen", "OU812", "Warner Bros.", 1988, "Compact Disc" },
  576. };
  577.  
  578. /*---------------------------------------------------------------------------*/
  579.  
  580. /* buffer area to use for editing Albums "file" */
  581.  
  582. static char artist[25+1];
  583. static char title[30+1];
  584. static char label[15+1];
  585. static int  copyright;
  586. static char media[15+1];
  587.  
  588. /*---------------------------------------------------------------------------*/
  589.  
  590. /* media type table */
  591.  
  592. static PSTR media_types[] = { "Compact Disc", "Cassette", "Record", "DAT",
  593.                               "Mini Disc", "DCC", "Open Reel", "8-Track",
  594.                               NULL };
  595.  
  596. /*---------------------------------------------------------------------------*/
  597.  
  598. int FAR PASCAL AlbumDlgProc( HWND hDlg, unsigned message, WORD wParam,
  599.                              LONG lParam )
  600. {
  601.     static HFORM hform = NULL;
  602.     static int curr_rec = 0;
  603.     int new_rec;
  604.  
  605.     switch( message ) {
  606.         case WM_INITDIALOG:
  607.             curr_rec = get_record( 1 );
  608.             hform = form_begin( hDlg, FMF_UPDATE, NULL );
  609.             form_set_help( hform, help_file_name, 0 );
  610.             field_define( hform, IDD_RECNO, &curr_rec, FDT_INTEGER, "999",
  611.                           FDF_NOTEDIT, NULL, 0, IDH_RECNO );
  612.             field_define( hform, IDD_ARTIST, artist, FDT_STRING, "?(25)",
  613.                           FDF_NOTBLANK, NULL, 0, IDH_ARTIST );
  614.             field_define( hform, IDD_TITLE, title, FDT_STRING, "?(30)",
  615.                           FDF_NONE, NULL, 0, IDH_TITLE );
  616.             field_define( hform, IDD_LABEL, label, FDT_STRING, "?(15)",
  617.                           FDF_NONE, NULL, 0, IDH_LABEL );
  618.             field_define( hform, IDD_COPYRIGHT, ©right, FDT_INTEGER, "<1><9>99",
  619.                           FDF_COMPLETE, NULL, 0, IDH_COPR );
  620.             field_define( hform, IDD_MEDIA, media, FDT_STRING, "?(15)",
  621.                           FDF_COMBO | FDF_NOTBLANK, NULL, 0, IDH_MEDIA );
  622.             keystat_define( hform, IDD_INSERT,   KSM_INSERT,   "[Ins]",  "" );
  623.             keystat_define( hform, IDD_CAPSLOCK, KSM_CAPSLOCK, "[Caps]", "" );
  624.             keystat_define( hform, IDD_NUMLOCK,  KSM_NUMLOCK,  "[Num]",  "" );
  625.             form_end( hform );
  626.             fill_media_list_box( hDlg );
  627.             return( TRUE );
  628.  
  629.         case WM_COMMAND:
  630.             switch( wParam ) {
  631.                 case IDOK:
  632.                     form_ok( hform );
  633.                     EndDialog( hDlg, TRUE );
  634.                     return( TRUE );
  635.                 case IDCANCEL:
  636.                     form_cancel( hform );
  637.                     EndDialog( hDlg, TRUE );
  638.                     return( TRUE );
  639.                 case IDD_PREVIOUS:
  640.                 case IDD_NEXT:
  641.                     if( form_validate( hform ) != NULL ) return( TRUE );
  642.                     if( form_has_changed( hform ) ) {
  643.                         if( okay_to_save_changes( hDlg ) ) {
  644.                             form_save( hform );
  645.                             update_record( curr_rec );
  646.                         }
  647.                     }
  648.                     new_rec = ( wParam == IDD_PREVIOUS )
  649.                                  ? ( curr_rec - 1 ) : ( curr_rec + 1 );
  650.                     new_rec = get_record( new_rec );
  651.                     if( new_rec == -1 )
  652.                         MessageBeep( 0 );
  653.                     else
  654.                         curr_rec = new_rec;
  655.                     form_load( hform );
  656.                     PostMessage( hDlg, WM_COMMAND, GOTO_ARTIST, 0 );
  657.                     return( TRUE );
  658.                 case GOTO_ARTIST:
  659.                     SetFocus( GetDlgItem( hDlg, IDD_ARTIST ) );
  660.                     return( TRUE );
  661.             }
  662.             break;
  663.         case WM_CLOSE:
  664.             SendMessage( hDlg, WM_COMMAND, IDCANCEL, 0 );
  665.             return( TRUE );
  666.     }
  667.     return( FALSE );
  668. }
  669.  
  670. /*---------------------------------------------------------------------------*/
  671.  
  672. static void fill_media_list_box( HWND hDlg )
  673. {
  674.     int i;
  675.     for( i = 0 ; media_types[i] != NULL ; i++ ) {
  676.         SendMessage( GetDlgItem( hDlg, IDD_MEDIA ), CB_ADDSTRING, 0,
  677.                      (LONG) ( (LPSTR) media_types[i] ) );
  678.     }
  679. }
  680.  
  681. /*---------------------------------------------------------------------------*/
  682.  
  683. /* gets a record from the Albums "file" */
  684.  
  685. static int get_record( int recno )
  686. {
  687.     int last_rec, ofs;
  688.  
  689.     last_rec = sizeof( albums ) / sizeof( albums[0] );
  690.     if( recno < 1 || recno > last_rec ) return( -1 );
  691.     ofs = recno - 1;
  692.     lstrcpy( artist, albums[ofs].artist );
  693.     lstrcpy( title,  albums[ofs].title );
  694.     lstrcpy( label,  albums[ofs].label );
  695.     copyright = albums[ofs].copyright;
  696.     lstrcpy( media,  albums[ofs].media );
  697.     return( recno );
  698. }
  699.  
  700. /*---------------------------------------------------------------------------*/
  701.  
  702. static BOOL okay_to_save_changes( HWND hDlg )
  703. {
  704.     return( MessageBox( hDlg, "Record has changed.  Save changes?",
  705.                         "Record Has Changed",
  706.                         MB_ICONQUESTION | MB_YESNO ) == IDYES );
  707. }
  708.  
  709. /*---------------------------------------------------------------------------*/
  710.  
  711. /* updates a record in the Albums "file" */
  712.  
  713. static void update_record( int recno )
  714. {
  715.     int ofs;
  716.  
  717.     ofs = recno - 1;
  718.     lstrcpy( albums[ofs].artist, artist );
  719.     lstrcpy( albums[ofs].title, title );
  720.     lstrcpy( albums[ofs].label, label );
  721.     albums[ofs].copyright = copyright;
  722.     lstrcpy( albums[ofs].media, media );
  723. }
  724.  
  725. /*****************************************************************************/
  726. /*---------------------------------------------------------------------------*/
  727. /*---------------------------------------------------------------------------*/
  728. /*------------------------/                          \-----------------------*/
  729. /*------------------------    Upload File Dialog      -----------------------*/
  730. /*------------------------\                          /-----------------------*/
  731. /*---------------------------------------------------------------------------*/
  732. /*---------------------------------------------------------------------------*/
  733. /*****************************************************************************/
  734.  
  735. /* prototypes for Upload File dialog */
  736.  
  737. static void fill_list_boxes( HWND hDlg, PSTR pathspec );
  738.  
  739. /*---------------------------------------------------------------------------*/
  740.  
  741. /* protocol name table */
  742.  
  743. static PSTR protocols[] = { "Xmodem", "Ymodem", "Zmodem" };
  744.  
  745. /*---------------------------------------------------------------------------*/
  746.  
  747. int FAR PASCAL UploadDlgProc( HWND hDlg, unsigned message, WORD wParam,
  748.                               LONG lParam )
  749. {
  750.     static HFORM hform = NULL;
  751.     static int protocol = 0, hangup;
  752.     static char path_spec[81], file_name[13];
  753.     static HFIELD hfile_name;
  754.  
  755.     switch( message ) {
  756.         case WM_INITDIALOG:
  757.             hform = form_begin( hDlg, FMF_NONE, perror_func );
  758.             form_set_help( hform, help_file_name, 0 );
  759.             hfile_name = field_define( hform, IDD_FILENAME, file_name,
  760.                                        FDT_STRING, "F(12)", FDF_NOTBLANK,
  761.                                        pcheck_file_name, BAD_FILENAME,
  762.                                        IDH_FILENAME );
  763.             form_set_enable_link( hform, (HANDLE) hfile_name, ELC_BLANK, IDOK,
  764.                                   FALSE );
  765.             generic_define( hform, IDD_FILEBOX, IDH_FILEBOX );
  766.             generic_define( hform, IDD_DIRBOX, IDH_DIRBOX );
  767.             button_define( hform, IDD_XMODEM, &protocol, 1, 0, 0,
  768.                            BTF_UPDATE, IDH_XMODEM );
  769.             button_define( hform, IDD_YMODEM, &protocol, 1, 1, 0,
  770.                            BTF_UPDATE, IDH_YMODEM );
  771.             button_define( hform, IDD_ZMODEM, &protocol, 1, 2, 0,
  772.                            BTF_UPDATE, IDH_ZMODEM );
  773.             button_define( hform, IDD_HANGUP, &hangup, 0, TRUE, FALSE,
  774.                            BTF_NONE, IDH_HANGUP );
  775.             form_end( hform );
  776.             fill_list_boxes( hDlg, "*.*" );
  777.             return( TRUE );
  778.  
  779.         case WM_COMMAND:
  780.             switch( wParam ) {
  781.                 case IDOK:
  782.                     form_ok( hform );
  783.                     GetDlgItemText( hDlg, IDD_PATHSPEC, path_spec, 80 );
  784.                     EndDialog( hDlg, TRUE );
  785.                     wsprintf( tbuf, "Uploading the file:  %s%s%s\n"
  786.                               "Using the %s protocol.\n"
  787.                               "Will %shang up after transfer.",
  788.                               (LPSTR) path_spec,
  789.                               *( path_spec + lstrlen( path_spec ) - 1 )
  790.                               == '\\' ? (LPSTR) "" : (LPSTR) "\\",
  791.                               (LPSTR) file_name,
  792.                               (LPSTR) protocols[protocol],
  793.                               hangup ? (LPSTR) "" : (LPSTR) "not " );
  794.                     MessageBox( NULL, tbuf, "Upload File", MB_OK );
  795.                     return( TRUE );
  796.  
  797.                 case IDCANCEL:
  798.                     form_cancel( hform );
  799.                     EndDialog( hDlg, TRUE );
  800.                     return( TRUE );
  801.  
  802.                 case IDD_FILEBOX:
  803.                     if( HIWORD( lParam ) == LBN_SELCHANGE ) {
  804.                         SendDlgItemMessage( hDlg, IDD_FILEBOX, LB_GETTEXT,
  805.                                             (int) SendDlgItemMessage( hDlg,
  806.                                             IDD_FILEBOX, LB_GETCURSEL, 0, 0 ),
  807.                                             (LONG) ( (LPSTR) tbuf ) );
  808.                         field_set_text( hfile_name, tbuf, TRUE );
  809.                         return( TRUE );
  810.                     }
  811.                     if( HIWORD( lParam ) == LBN_DBLCLK ) {
  812.                         PostMessage( hDlg, WM_COMMAND, IDOK,
  813.                                      (LONG) GetDlgItem( hDlg, IDOK ) );
  814.                         return( TRUE );
  815.                     }
  816.                     break;
  817.  
  818.                 case IDD_DIRBOX:
  819.                     if( HIWORD( lParam ) == LBN_DBLCLK ) {
  820.                         DlgDirSelect( hDlg, path_spec, IDD_DIRBOX );
  821.                         field_set_text( hfile_name, "", TRUE );
  822.                         lstrcat( path_spec, "*.*" );
  823.                         fill_list_boxes( hDlg, path_spec );
  824.                         return( TRUE );
  825.                     }
  826.                     break;
  827.             }
  828.             break;
  829.         case WM_CLOSE:
  830.             SendMessage( hDlg, WM_COMMAND, IDCANCEL, 0 );
  831.             return( TRUE );
  832.     }
  833.     return( FALSE );
  834. }
  835.  
  836. /*---------------------------------------------------------------------------*/
  837.  
  838. int FAR PASCAL check_file_name( HFORM hform, HFIELD hfield, LPSTR pbuf )
  839. {
  840.     char file_name[13];
  841.  
  842.     lstrcpy( file_name, pbuf );
  843.     str_trim_spaces( file_name );
  844.     return( ( SendDlgItemMessage( GetParent( GetFocus() ), IDD_FILEBOX,
  845.             LB_FINDSTRING, (WPARAM) -1, (LONG) ( (LPSTR) file_name ) ) == LB_ERR )
  846.             ? 1 : 0 );
  847. }
  848.  
  849. /*---------------------------------------------------------------------------*/
  850.  
  851. static void fill_list_boxes( HWND hDlg, PSTR pathspec )
  852. {
  853.     DlgDirList( hDlg, pathspec, IDD_FILEBOX, 0, 0x0001 | 0x0020 );
  854.     DlgDirList( hDlg, pathspec, IDD_DIRBOX, IDD_PATHSPEC, 0x0010 | 0x4000 |
  855.                 0x8000 );
  856. }
  857.  
  858. /*****************************************************************************/
  859. /*---------------------------------------------------------------------------*/
  860. /*---------------------------------------------------------------------------*/
  861. /*------------------------/                          \-----------------------*/
  862. /*------------------------   Numeric Fields Dialog     ----------------------*/
  863. /*------------------------\                          /-----------------------*/
  864. /*---------------------------------------------------------------------------*/
  865. /*---------------------------------------------------------------------------*/
  866. /*****************************************************************************/
  867.  
  868. int FAR PASCAL NumericDlgProc( HWND hDlg, unsigned message, WORD wParam,
  869.                               LONG lParam )
  870. {
  871.     static HFORM hform = NULL;
  872.     static long std = 0;
  873.     static unsigned long zerofill = 0;
  874.     static unsigned int calc = 0;
  875.     static double stddec = 0.0, calcdec = 0.0, real= 0.0;
  876.  
  877.     switch( message ) {
  878.  
  879.         case WM_INITDIALOG:
  880.             hform = form_begin( hDlg, FMF_OVERTYPE | FMF_NOSELECT | FMF_UPDATE,
  881.                                 NULL );
  882.             field_define( hform, IDD_STD, &std, FDT_LONG,
  883.                           "N(7)", FDF_NUMERIC, NULL, 0, 0 );
  884.             field_define( hform, IDD_STDDEC, &stddec, FDT_DOUBLE,
  885.                           "9(5).99", FDF_NUMERIC, NULL, 0, 0 );
  886.             field_define( hform, IDD_ZEROFILL, &zerofill, FDT_ULONG,
  887.                           "9(9)", FDF_NUMERIC | FDF_ZEROFILL, NULL, 0, 0 );
  888.             field_define( hform, IDD_CALC, &calc, FDT_UNSIGNED,
  889.                           "<0123456 >9(4)", FDF_CALCNUM | FDF_VLEAVFLD,
  890.                           NULL, 0, 0 );
  891.             field_define( hform, IDD_CALCDEC, &calcdec, FDT_DOUBLE,
  892.                           "N,NNN,NNN.NN", FDF_CALCNUM, NULL, 0, 0 );
  893.             field_define( hform, IDD_REAL, &real, FDT_DOUBLE,
  894.                           "#(9)", FDF_NUMERIC, NULL, 0, 0 );
  895.             keystat_define( hform, IDD_INSERT, KSM_INSERT, "(Ins)", "(Ovr)" );
  896.             form_end( hform );
  897.             return( TRUE );
  898.  
  899.         case WM_COMMAND:
  900.             switch( wParam ) {
  901.                 case IDOK:
  902.                     form_ok( hform );
  903.                     EndDialog( hDlg, TRUE );
  904.                     sprintf( tbuf, "%ld\t%.2lf\n%lu\t%u\n%.2lf\n%le\n", std,
  905.                              stddec, zerofill, calc, calcdec, real );
  906.                     MessageBox( NULL, tbuf, "Field Contents", MB_OK );
  907.                     return( TRUE );
  908.                 case IDCANCEL:
  909.                     form_cancel( hform );
  910.                     EndDialog( hDlg, TRUE );
  911.                     return( TRUE );
  912.             }
  913.             break;
  914.  
  915.         case WM_CLOSE:
  916.             SendMessage( hDlg, WM_COMMAND, IDCANCEL, 0 );
  917.             return( TRUE );
  918.  
  919.     }
  920.     return( FALSE );
  921. }
  922.  
  923.